package com.icim.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.icim.entity.His_ret_prd_info;
import com.icim.entity.Ret_wo;

@Repository
public class HisRetPrdInfoDao {
	@Resource
	private JdbcTemplate icimHisJdbcTemplate;

	
	private His_ret_prd_info setEntityByRs(ResultSet rs)
			throws SQLException {
		His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
		hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
		hisRetPrdInfo.setPallet_id(rs.getString("PALLET_ID"));
		hisRetPrdInfo.setShip_box_id_fk(rs
				.getString("SHIP_BOX_ID_FK"));
		hisRetPrdInfo.setPrd_stat(rs.getString("PRD_STAT"));
		hisRetPrdInfo.setSta_time_d(rs.getDouble("STA_TIME_D"));
		hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
		hisRetPrdInfo.setEvt_timestamp(rs.getTimestamp("EVT_TIMESTAMP"));
		hisRetPrdInfo.setEvt_usr(rs.getString("EVT_USR"));
		hisRetPrdInfo.setSht_ope_msg(rs
				.getString("SHT_OPE_MSG"));
		hisRetPrdInfo.setMdl_id_fk(rs.getString("MDL_ID_FK"));
		hisRetPrdInfo.setGroup_id(rs.getString("GROUP_ID"));
		hisRetPrdInfo.setMtrl_product_id(rs
				.getString("MTRL_PROD_ID_FK"));
		hisRetPrdInfo.setPrd_grade(rs.getString("PRD_GRADE"));
		hisRetPrdInfo.setCr_ope_id_fk(rs
				.getString("CR_OPE_ID_FK"));
		hisRetPrdInfo.setNx_ope_id_fk(rs
				.getString("NX_OPE_ID_FK"));
		hisRetPrdInfo.setCr_tool_id_fk(rs
				.getString("CR_TOOL_ID_FK"));
		hisRetPrdInfo.setNx_tool_id_fk(rs.getString("NX_TOOL_ID_FK"));
		hisRetPrdInfo.setLine_id(rs.getString("LINE_ID"));
		hisRetPrdInfo.setFab_id(rs.getString("FAB_ID"));
		hisRetPrdInfo.setProc_flg(rs.getString("PROC_FLG"));
		hisRetPrdInfo.setSo_id_fk(rs.getString("SO_ID_FK"));
		hisRetPrdInfo.setRsn_dept1(rs.getString("RSN_DEPT1"));
		hisRetPrdInfo.setDs_recipe_id(rs
				.getString("DS_RECIPE_ID"));
		hisRetPrdInfo.setOqc_skip_flg(rs
				.getString("OQC_SKIP_FLG"));
		hisRetPrdInfo.setRsn_cate1(rs.getString("RSN_CATE1"));
		return hisRetPrdInfo;
	}
	
	public List<His_ret_prd_info> findSheets(List<Ret_wo> woList,
			Timestamp beginTimestamp, Timestamp endTimestamp) {

		StringBuffer sqlBuffer = new StringBuffer();

		sqlBuffer
				.append(" SELECT *  FROM HIS_RET_PRD_INFO ");

		sqlBuffer.append(" WHERE  EVT_TIMESTAMP >= ? AND EVT_TIMESTAMP <? ");

		sqlBuffer.append(" AND EVT_CATE IN ('LGON','LGOF','WHIN','WHOT','STBI') ");
		if (woList.isEmpty()) {
			return new ArrayList<His_ret_prd_info>();
		}

		sqlBuffer.append(" AND WO_ID_FK IN ( ");
		for (Ret_wo retWo : woList) {
			sqlBuffer.append("'").append(retWo.getWo_id()).append("'");
			if (woList.indexOf(retWo) < woList.size() - 1) {
				sqlBuffer.append(",");
			}
		}
		sqlBuffer.append(")");

		return icimHisJdbcTemplate.query(sqlBuffer.toString(), new Object[] {
				beginTimestamp, endTimestamp },
				new RowMapper<His_ret_prd_info>() {

					@Override
					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						return setEntityByRs(rs);
					}
					
				});
	}
	
//	public List<His_ret_prd_info> findSheets(List<Ret_wo> woList,
//			Double dBeginTime, Double dEndTime,Timestamp indexTimestamp) {
//
//		StringBuffer sqlBuffer = new StringBuffer();
//
//		sqlBuffer
//				.append(" SELECT *  FROM HIS_RET_PRD_INFO ");
//
//		sqlBuffer.append(" WHERE EVT_TIMESTAMP > ?  ");
//
//		sqlBuffer.append(" AND EVT_CATE IN ('LGON','LGOF','WHIN','WHOT','STBI') ");
//		if (woList.isEmpty()) {
//			return new ArrayList<His_ret_prd_info>();
//		}
//
//		sqlBuffer.append(" AND WO_ID_FK IN ( ");
//		for (Ret_wo retWo : woList) {
//			sqlBuffer.append("'").append(retWo.getWo_id()).append("'");
//			if (woList.indexOf(retWo) < woList.size() - 1) {
//				sqlBuffer.append(",");
//			}
//		}
//		sqlBuffer.append(")");
//		sqlBuffer.append(" AND  STA_TIME_D >= ? AND STA_TIME_D <= ? ");
//
//		return icimHisJdbcTemplate.query(sqlBuffer.toString(), new Object[] {
//				indexTimestamp,dBeginTime, dEndTime },
//				new RowMapper<His_ret_prd_info>() {
//
//					@Override
//					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
//							throws SQLException {
//						return setEntityByRs(rs);
//					}
//					
//				});
//	}

//	public List<His_ret_prd_info> findLogoffRecordsByOpe(List<Ret_wo> woList,
//			String[] opeIds, Double dBeginTimestamp, Double dEndTimestamp,Timestamp indexTimestamp) {
//
//		StringBuffer sqlBuffer = new StringBuffer();
//
//		sqlBuffer
//				.append(" SELECT PRD_SEQ_ID,PALLET_ID,SHIP_BOX_ID_FK,PRD_STAT,STA_TIME_D,");
//		sqlBuffer
//				.append(" PRD_SEQ_ID,PALLET_ID,SHIP_BOX_ID_FK,PRD_STAT,STA_TIME_D,");
//		sqlBuffer.append(" EVT_CATE,EVT_USR,SHT_OPE_MSG,MDL_ID_FK,GROUP_ID,");
//		sqlBuffer
//				.append(" MTRL_PROD_ID_FK,PRD_GRADE,CR_OPE_ID_FK,NX_OPE_ID_FK,");
//		sqlBuffer.append(" LINE_ID,FAB_ID,PROC_FLG,SO_ID_FK,RSN_DEPT1,");
//		sqlBuffer.append(" CR_OPE_VER_FK,NX_OPE_VER_FK,DS_RECIPE_ID");
//		sqlBuffer.append(" FROM HIS_RET_PRD_INFO ");
//
//		sqlBuffer.append(" WHERE EVT_TIMESTAMP >  ?  ");
//
//		sqlBuffer.append(" AND EVT_CATE IN ('LGOF') ");
//		sqlBuffer.append(" AND CR_OPE_ID_FK IN ( ");
//		for (int i = 0; i < opeIds.length; i++) {
//			String opeId = opeIds[i];
//			sqlBuffer.append("'").append(opeId).append("'");
//			if (i < opeIds.length - 1) {
//				sqlBuffer.append(",");
//			}
//		}
//		sqlBuffer.append(" )");
//		if (woList.isEmpty()) {
//			return new ArrayList<His_ret_prd_info>();
//		}
//
//		sqlBuffer.append(" AND WO_ID_FK IN ( ");
//		for (Ret_wo retWo : woList) {
//			sqlBuffer.append("'").append(retWo.getWo_id()).append("'");
//			if (woList.indexOf(retWo) < woList.size() - 1) {
//				sqlBuffer.append(",");
//			}
//		}
//		sqlBuffer.append(")");
//		sqlBuffer.append(" AND STA_TIME_D >= ? AND STA_TIME_D <= ?");
//
//		return icimHisJdbcTemplate.query(sqlBuffer.toString(), new Object[] {
//				indexTimestamp,dBeginTimestamp, dEndTimestamp },
//				new RowMapper<His_ret_prd_info>() {
//
//					@Override
//					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
//							throws SQLException {
//						His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
//						hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
//						hisRetPrdInfo.setPallet_id(rs.getString("PALLET_ID"));
//						hisRetPrdInfo.setShip_box_id_fk(rs
//								.getString("SHIP_BOX_ID_FK"));
//						hisRetPrdInfo.setPrd_stat(rs.getString("PRD_STAT"));
//						hisRetPrdInfo.setSta_time_d(rs.getDouble("STA_TIME_D"));
//						hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
//						hisRetPrdInfo.setEvt_usr(rs.getString("EVT_USR"));
//						hisRetPrdInfo.setSht_ope_msg(rs
//								.getString("SHT_OPE_MSG"));
//						hisRetPrdInfo.setMdl_id_fk(rs.getString("MDL_ID_FK"));
//						hisRetPrdInfo.setGroup_id(rs.getString("GROUP_ID"));
//						hisRetPrdInfo.setMtrl_product_id(rs
//								.getString("MTRL_PROD_ID_FK"));
//						hisRetPrdInfo.setPrd_grade(rs.getString("PRD_GRADE"));
//						hisRetPrdInfo.setCr_ope_id_fk(rs
//								.getString("CR_OPE_ID_FK"));
//						hisRetPrdInfo.setCr_ope_ver_fk(rs
//								.getString("CR_OPE_VER_FK"));
//						hisRetPrdInfo.setNx_ope_id_fk(rs
//								.getString("NX_OPE_ID_FK"));
//						hisRetPrdInfo.setNx_ope_ver_fk(rs
//								.getString("NX_OPE_VER_FK"));
//						hisRetPrdInfo.setLine_id(rs.getString("LINE_ID"));
//						hisRetPrdInfo.setFab_id(rs.getString("FAB_ID"));
//						hisRetPrdInfo.setProc_flg(rs.getString("PROC_FLG"));
//						hisRetPrdInfo.setSo_id_fk(rs.getString("SO_ID_FK"));
//						hisRetPrdInfo.setRsn_dept1(rs.getString("RSN_DEPT1"));
//						hisRetPrdInfo.setDs_recipe_id(rs
//								.getString("DS_RECIPE_ID"));
//						return hisRetPrdInfo;
//					}
//				});
//	}
	
	public List<His_ret_prd_info> findLogoffRecordsByOpe(List<Ret_wo> woList,
			String[] opeIds, Timestamp beginTimestamp, Timestamp endTimestamp) {

		StringBuffer sqlBuffer = new StringBuffer();

		sqlBuffer
				.append(" SELECT PRD_SEQ_ID,PALLET_ID,SHIP_BOX_ID_FK,PRD_STAT,STA_TIME_D,");
		sqlBuffer
				.append(" PRD_SEQ_ID,PALLET_ID,SHIP_BOX_ID_FK,PRD_STAT,STA_TIME_D,");
		sqlBuffer.append(" EVT_CATE,EVT_USR,SHT_OPE_MSG,MDL_ID_FK,GROUP_ID,");
		sqlBuffer
				.append(" MTRL_PROD_ID_FK,PRD_GRADE,CR_OPE_ID_FK,NX_OPE_ID_FK,");
		sqlBuffer.append(" LINE_ID,FAB_ID,PROC_FLG,SO_ID_FK,RSN_DEPT1,");
		sqlBuffer.append(" CR_OPE_VER_FK,NX_OPE_VER_FK,DS_RECIPE_ID");
		sqlBuffer.append(" FROM HIS_RET_PRD_INFO ");

		sqlBuffer.append(" WHERE EVT_TIMESTAMP >=? AND EVT_TIMESTAMP < ?");

		sqlBuffer.append(" AND EVT_CATE IN ('LGOF') ");
		sqlBuffer.append(" AND CR_OPE_ID_FK IN ( ");
		for (int i = 0; i < opeIds.length; i++) {
			String opeId = opeIds[i];
			sqlBuffer.append("'").append(opeId).append("'");
			if (i < opeIds.length - 1) {
				sqlBuffer.append(",");
			}
		}
		sqlBuffer.append(" )");
		if (woList.isEmpty()) {
			return new ArrayList<His_ret_prd_info>();
		}

		sqlBuffer.append(" AND WO_ID_FK IN ( ");
		for (Ret_wo retWo : woList) {
			sqlBuffer.append("'").append(retWo.getWo_id()).append("'");
			if (woList.indexOf(retWo) < woList.size() - 1) {
				sqlBuffer.append(",");
			}
		}
		sqlBuffer.append(")");

		return icimHisJdbcTemplate.query(sqlBuffer.toString(), new Object[] {
				beginTimestamp, endTimestamp },
				new RowMapper<His_ret_prd_info>() {

					@Override
					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
						hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
						hisRetPrdInfo.setPallet_id(rs.getString("PALLET_ID"));
						hisRetPrdInfo.setShip_box_id_fk(rs
								.getString("SHIP_BOX_ID_FK"));
						hisRetPrdInfo.setPrd_stat(rs.getString("PRD_STAT"));
						hisRetPrdInfo.setSta_time_d(rs.getDouble("STA_TIME_D"));
						hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
						hisRetPrdInfo.setEvt_usr(rs.getString("EVT_USR"));
						hisRetPrdInfo.setSht_ope_msg(rs
								.getString("SHT_OPE_MSG"));
						hisRetPrdInfo.setMdl_id_fk(rs.getString("MDL_ID_FK"));
						hisRetPrdInfo.setGroup_id(rs.getString("GROUP_ID"));
						hisRetPrdInfo.setMtrl_product_id(rs
								.getString("MTRL_PROD_ID_FK"));
						hisRetPrdInfo.setPrd_grade(rs.getString("PRD_GRADE"));
						hisRetPrdInfo.setCr_ope_id_fk(rs
								.getString("CR_OPE_ID_FK"));
						hisRetPrdInfo.setCr_ope_ver_fk(rs
								.getString("CR_OPE_VER_FK"));
						hisRetPrdInfo.setNx_ope_id_fk(rs
								.getString("NX_OPE_ID_FK"));
						hisRetPrdInfo.setNx_ope_ver_fk(rs
								.getString("NX_OPE_VER_FK"));
						hisRetPrdInfo.setLine_id(rs.getString("LINE_ID"));
						hisRetPrdInfo.setFab_id(rs.getString("FAB_ID"));
						hisRetPrdInfo.setProc_flg(rs.getString("PROC_FLG"));
						hisRetPrdInfo.setSo_id_fk(rs.getString("SO_ID_FK"));
						hisRetPrdInfo.setRsn_dept1(rs.getString("RSN_DEPT1"));
						hisRetPrdInfo.setDs_recipe_id(rs
								.getString("DS_RECIPE_ID"));
						return hisRetPrdInfo;
					}
				});
	}

	public List<His_ret_prd_info> listSheetHistory(String sheetId) {
		String sql = "SELECT * FROM HIS_RET_PRD_INFO WHERE PRD_SEQ_ID = ? ORDER BY EVT_TIMESTAMP ";
		return icimHisJdbcTemplate.query(sql, new Object[] { sheetId },
				new RowMapper<His_ret_prd_info>() {

					@Override
					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
						hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
						hisRetPrdInfo.setPallet_id(rs.getString("PALLET_ID"));
						hisRetPrdInfo.setShip_box_id_fk(rs
								.getString("SHIP_BOX_ID_FK"));
						hisRetPrdInfo.setPrd_stat(rs.getString("PRD_STAT"));
						hisRetPrdInfo.setSta_time_d(rs.getDouble("STA_TIME_D"));
						hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
						hisRetPrdInfo.setEvt_usr(rs.getString("EVT_USR"));
						hisRetPrdInfo.setSht_ope_msg(rs
								.getString("SHT_OPE_MSG"));
						hisRetPrdInfo.setMdl_id_fk(rs.getString("MDL_ID_FK"));
						hisRetPrdInfo.setGroup_id(rs.getString("GROUP_ID"));
						hisRetPrdInfo.setMtrl_product_id(rs
								.getString("MTRL_PROD_ID_FK"));
						hisRetPrdInfo.setPrd_grade(rs.getString("PRD_GRADE"));
						hisRetPrdInfo.setCr_ope_id_fk(rs
								.getString("CR_OPE_ID_FK"));
						hisRetPrdInfo.setCr_ope_ver_fk(rs
								.getString("CR_OPE_VER_FK"));
						hisRetPrdInfo.setNx_ope_id_fk(rs
								.getString("NX_OPE_ID_FK"));
						hisRetPrdInfo.setNx_ope_ver_fk(rs
								.getString("NX_OPE_VER_FK"));
						hisRetPrdInfo.setLine_id(rs.getString("LINE_ID"));
						hisRetPrdInfo.setFab_id(rs.getString("FAB_ID"));
						hisRetPrdInfo.setProc_flg(rs.getString("PROC_FLG"));
						hisRetPrdInfo.setSo_id_fk(rs.getString("SO_ID_FK"));
						hisRetPrdInfo.setRsn_dept1(rs.getString("RSN_DEPT1"));
						hisRetPrdInfo.setDs_recipe_id(rs
								.getString("DS_RECIPE_ID"));
						hisRetPrdInfo.setEvt_timestamp(rs
								.getTimestamp("EVT_TIMESTAMP"));
						return hisRetPrdInfo;
					}
				});
	}

	public Map<String, His_ret_prd_info> findSheetsStbiHistory(
			String[] sheetIds) {
		StringBuffer sqlBuffer = new StringBuffer(
				"SELECT * FROM HIS_RET_PRD_INFO WHERE PRD_SEQ_ID in (");
		int cnt = sheetIds.length;
		for (int i = 0; i < cnt; i++) {
			String sheetId = sheetIds[i];
			sqlBuffer.append("'").append(sheetId).append("'");
			if (i < cnt - 1) {
				sqlBuffer.append(",");
			}
		}
		sqlBuffer.append(") AND EVT_CATE = 'STBI'  ORDER BY PRD_SEQ_ID,EVT_TIMESTAMP");
		List<His_ret_prd_info> sheetsHistory = icimHisJdbcTemplate.query(
				sqlBuffer.toString(), new RowMapper<His_ret_prd_info>() {

					@Override
					public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
						hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
						hisRetPrdInfo.setPallet_id(rs.getString("PALLET_ID"));
						hisRetPrdInfo.setShip_box_id_fk(rs
								.getString("SHIP_BOX_ID_FK"));
						hisRetPrdInfo.setPrd_stat(rs.getString("PRD_STAT"));
						hisRetPrdInfo.setSta_time_d(rs.getDouble("STA_TIME_D"));
						hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
						hisRetPrdInfo.setEvt_usr(rs.getString("EVT_USR"));
						hisRetPrdInfo.setSht_ope_msg(rs
								.getString("SHT_OPE_MSG"));
						hisRetPrdInfo.setMdl_id_fk(rs.getString("MDL_ID_FK"));
						hisRetPrdInfo.setGroup_id(rs.getString("GROUP_ID"));
						hisRetPrdInfo.setMtrl_product_id(rs
								.getString("MTRL_PROD_ID_FK"));
						hisRetPrdInfo.setPrd_grade(rs.getString("PRD_GRADE"));
						hisRetPrdInfo.setCr_ope_id_fk(rs
								.getString("CR_OPE_ID_FK"));
						hisRetPrdInfo.setCr_ope_ver_fk(rs
								.getString("CR_OPE_VER_FK"));
						hisRetPrdInfo.setNx_ope_id_fk(rs
								.getString("NX_OPE_ID_FK"));
						hisRetPrdInfo.setNx_ope_ver_fk(rs
								.getString("NX_OPE_VER_FK"));
						hisRetPrdInfo.setLine_id(rs.getString("LINE_ID"));
						hisRetPrdInfo.setFab_id(rs.getString("FAB_ID"));
						hisRetPrdInfo.setProc_flg(rs.getString("PROC_FLG"));
						hisRetPrdInfo.setSo_id_fk(rs.getString("SO_ID_FK"));
						hisRetPrdInfo.setRsn_dept1(rs.getString("RSN_DEPT1"));
						hisRetPrdInfo.setDs_recipe_id(rs
								.getString("DS_RECIPE_ID"));
						hisRetPrdInfo.setEvt_timestamp(rs
								.getTimestamp("EVT_TIMESTAMP"));
						return hisRetPrdInfo;
					}
				});

		Map<String, His_ret_prd_info> sheetHisMap = new HashMap<String, His_ret_prd_info>();

		for (His_ret_prd_info hisRetPrdInfo : sheetsHistory) {
			String prdSeqId = hisRetPrdInfo.getPrd_seq_id();
			sheetHisMap.put(prdSeqId,hisRetPrdInfo);
		}
		return sheetHisMap;

	}
	
	
	public List<His_ret_prd_info> findSheetsHistoryForRet005(
        String sheetId) {
//	  SELECT t.wo_id_fk,w.cus_info_snd,t.mtrl_prod_id_fk,t.mtrl_box_id_fk,t.prd_seq_id,t.cr_tool_id_fk,t.evt_cate,t.evt_timestamp,t.c_rubbing_time,t.t_rubbing_time 
//      FROM his_ret_prd_info t LEFT JOIN ret_wo w ON t.wo_id_fk = w.wo_id
//      WHERE t.cr_ope_id_fk = 'JB-08' AND t.prd_seq_id IN ('1234QAZX') AND t.evt_cate IN ('LGON','LGOF') 
//      ORDER BY t.evt_timestamp DESC LIMIT 2
    String sql = "SELECT t.wo_id_fk,w.cus_info_fst,w.fm_mdl_id_fk,t.mtrl_prod_id_fk,t.mtrl_box_id_fk,t.prd_seq_id,t.cr_tool_id_fk,t.evt_cate,t.evt_timestamp,t.c_rubbing_time,t.t_rubbing_time "+
            "FROM his_ret_prd_info t LEFT JOIN ret_wo w ON t.wo_id_fk = w.wo_id WHERE t.cr_ope_id_fk = 'UNT-000PG' AND t.prd_seq_id = '"+sheetId+"' AND t.evt_cate IN ('LGON','LGOF') ORDER BY t.evt_timestamp DESC LIMIT 2";
    System.out.println(sql);
    List<His_ret_prd_info> sheetsHistory = icimHisJdbcTemplate.query(
        sql, new RowMapper<His_ret_prd_info>() {

                @Override
                public His_ret_prd_info mapRow(ResultSet rs, int rowNum)
                        throws SQLException {
                    His_ret_prd_info hisRetPrdInfo = new His_ret_prd_info();
                    hisRetPrdInfo.setWo_id_fk(rs.getString("WO_ID_FK"));
                    hisRetPrdInfo.setCus_info_fst(rs.getString("CUS_INFO_FST"));
                    hisRetPrdInfo.setFm_mdl_id_fk(rs.getString("FM_MDL_ID_FK"));
                    hisRetPrdInfo.setMtrl_prod_id_fk(rs.getString("MTRL_PROD_ID_FK"));
                    hisRetPrdInfo.setMtrl_box_id_fk(rs.getString("MTRL_BOX_ID_FK"));
                    hisRetPrdInfo.setPrd_seq_id(rs.getString("PRD_SEQ_ID"));
                    hisRetPrdInfo.setCr_tool_id_fk(rs.getString("CR_TOOL_ID_FK"));
                    hisRetPrdInfo.setEvt_cate(rs.getString("EVT_CATE"));
                    hisRetPrdInfo.setEvt_timestamp(rs.getTimestamp("EVT_TIMESTAMP"));
                    hisRetPrdInfo.setC_rubbing_time(String.valueOf(rs.getInt("C_RUBBING_TIME")));
                    hisRetPrdInfo.setT_rubbing_time(String.valueOf(rs.getInt("T_RUBBING_TIME")));
                    return hisRetPrdInfo;
                }
            });

    return sheetsHistory;

}
}
